package controllers

import (
	"XYZShell/daltool/models"
	"bytes"

	"github.com/astaxie/beego"
)

type MainController struct {
	beego.Controller
}

func (c *MainController) Get() {
	var codegen = models.NewCodeGen()
	dbs := codegen.GetDbs()
	var buf bytes.Buffer
	for _, str := range dbs {
		buf.WriteString("<option>")
		buf.WriteString(str)
		buf.WriteString("</opton>")
	}
	c.Data["Website"] = buf.String()
	c.TplName = "index.html"
}
func (c *MainController) GetTables() {
	var db = c.Ctx.Request.FormValue("db")
	var codegen = models.NewCodeGen()
	tbs := codegen.GetTables(db)
	c.Data["json"] = tbs
	c.ServeJSON()
}
func (this *MainController) GetColumns() {
	var db = this.Ctx.Request.FormValue("db")
	var tab = this.Ctx.Request.FormValue("tab")
	var codegen = models.NewCodeGen()
	cols := codegen.GetColumns(db, tab)
	this.Data["json"] = cols
	this.ServeJSON()
}
func (this *MainController) GenCode() {
	var code = make(map[string]string)
	var tfields = make(map[string]string)
	tfields["Name"] = "string"
	tfields["Age"] = "int"
	var codegen = models.NewCodeGen()
	code["code"] = codegen.CodeGen("test1", "users", tfields)
	this.Data["json"] = code
	this.ServeJSON()
	//insert
	//update
	//delete
	//select cou

}
